package com.bartender.drink.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.bartender.common.core.domain.entity.SysUser;
import com.bartender.common.core.domain.model.LoginUser;
import com.bartender.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.bartender.common.annotation.Log;
import com.bartender.common.core.controller.BaseController;
import com.bartender.common.core.domain.AjaxResult;
import com.bartender.common.enums.BusinessType;
import com.bartender.drink.domain.Drink;
import com.bartender.drink.service.IDrinkService;
import com.bartender.common.utils.poi.ExcelUtil;
import com.bartender.common.core.page.TableDataInfo;

/**
 * 酒品管理Controller
 * 
 * @author bartender
 * @date 2024-11-28
 */
@RestController
@RequestMapping("/drink/drink")
public class DrinkController extends BaseController
{
    @Autowired
    private IDrinkService drinkService;

    /**
     * 查询酒品管理列表
     */
    @PreAuthorize("@ss.hasPermi('drink:drink:list')")
    @GetMapping("/list")
    public TableDataInfo list(Drink drink)
    {
        startPage();
        List<Drink> list = drinkService.selectDrinkList(drink);
        return getDataTable(list);
    }

    @GetMapping("/list_front")
    public List<Drink> listFront(Drink drink, @RequestParam Long deptId)
    {
        drink.setDeptId(deptId);
        List<Drink> list = drinkService.selectDrinkListFront(drink);
        return list;
    }

    /**
     * 导出酒品管理列表
     */
    @PreAuthorize("@ss.hasPermi('drink:drink:export')")
    @Log(title = "酒品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Drink drink)
    {
        List<Drink> list = drinkService.selectDrinkList(drink);
        ExcelUtil<Drink> util = new ExcelUtil<Drink>(Drink.class);
        util.exportExcel(response, list, "酒品管理数据");
    }

    /**
     * 获取酒品管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('drink:drink:query')")
    @GetMapping(value = "/{drinkId}")
    public AjaxResult getInfo(@PathVariable("drinkId") Long drinkId)
    {
        return success(drinkService.selectDrinkByDrinkId(drinkId));
    }

    /**
     * 新增酒品管理
     */
    @PreAuthorize("@ss.hasPermi('drink:drink:add')")
    @Log(title = "酒品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Drink drink)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser currentUser = loginUser.getUser();
        // 获取当前登录用户
        Long deptId = currentUser.getDeptId(); // 获取当前用户的部门ID
        drink.setDeptId(deptId); // 设置部门ID到Drink对象中
        return toAjax(drinkService.insertDrink(drink));
    }

    /**
     * 修改酒品管理
     */
    @PreAuthorize("@ss.hasPermi('drink:drink:edit')")
    @Log(title = "酒品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Drink drink)
    {
        return toAjax(drinkService.updateDrink(drink));
    }

    /**
     * 删除酒品管理
     */
    @PreAuthorize("@ss.hasPermi('drink:drink:remove')")
    @Log(title = "酒品管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{drinkIds}")
    public AjaxResult remove(@PathVariable Long[] drinkIds)
    {
        return toAjax(drinkService.deleteDrinkByDrinkIds(drinkIds));
    }
}
